package exp02;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class G2 {
	static class Person implements Comparable<Person>{
	
		@Override
		public String toString() {
			return this.name;
		}
		public Person(String name, int y, int m, int d) {
			super();
			this.name = name;
			this.y = y;
			this.m = m;
			this.d = d;
		}
		@Override
		public int compareTo(Person that) {
			if(this.y!=that.y)return this.y-that.y;
			if(this.m!=that.m)return this.m-that.m;
			return this.d-that.d;
		}
		
		
		String name;
		int y,m,d;
	}
public static void main(String[] args) {
	int n=cin.nextInt();
	List<Person> persons=new ArrayList<Person>();
	System.err.println(persons.size());
	for(int i=0;i<n;i++) {
		String name=cin.next();
		int y=cin.nextInt();
		int m=cin.nextInt();
		int d=cin.nextInt();
		persons.add(new Person(name, y, m, d));
		
	}
	Collections.sort(persons);
	for(Person person:persons) {//Iterator
		System.out.println(person);
	}
//	Iterator<Person> it=persons.iterator();
//	while(it.hasNext()) {
//		System.out.println(it.next().m);
//	}
}
static Scanner cin=new Scanner(System.in);
}
